package com.alen.sun.config;

import com.alen.sun.interceptor.ElderlyInterceptor;
import com.alen.sun.interceptor.EmployeeInterceptor;
import com.alen.sun.interceptor.MessageInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    private final MessageInterceptor messageInterceptor;
    private final EmployeeInterceptor employeeInterceptor;
    private final ElderlyInterceptor elderlyInterceptor;

    @Autowired
    public WebConfig(MessageInterceptor messageInterceptor, EmployeeInterceptor employeeInterceptor, ElderlyInterceptor elderlyInterceptor) {
        this.messageInterceptor = messageInterceptor;
        this.employeeInterceptor = employeeInterceptor;
        this.elderlyInterceptor = elderlyInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加第一个拦截器
        registry.addInterceptor(messageInterceptor)
                .addPathPatterns("/messages/add");

        // 添加第二个拦截器
        registry.addInterceptor(employeeInterceptor)
                .addPathPatterns("/messages/list");

        // 添加第三个拦截器
        registry.addInterceptor(elderlyInterceptor)
                .addPathPatterns("/elderlys/getByEmp");
    }
}
